package org.micode.common.config.reader;

import org.micode.common.context.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

public class DefaultConfigReader implements IConfigReader {

    @Autowired
    private Environment environment;

    private Environment getEnvironment() {
        if (environment == null) {
            environment = SpringContextHolder.getBean(Environment.class);
        }

        return environment;
    }

    @Override
    public void loadAll() {
    }

    @Override
    public String readProperty(String name, String defaultValue) {
        return getEnvironment().containsProperty(name) ? getEnvironment().getProperty(name) : defaultValue;
    }

}
